import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import VueRouter from 'vue-router'
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
// 页面路由
import Index from './views/Index.vue'
import VideoDatail from './views/video/videoDatail.vue'
import Find from './views/find.vue'
import Login from './views/slot/login.vue'
import Zhuce from './views/slot/zhuce.vue'
import VideoUP from './views/videoUP.vue'
import Test from './views/text.vue'
import User from './views/user1.vue'
import Comvideo from './views/comvideo.vue'
Vue.config.productionTip = false
Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.prototype.$axios = axios;
let router = new VueRouter({
  mode: 'history', //解决访问路径#问题
  //路由配置
  routes: [{
      path: '/',
      component: Index
    },
    {
      path: '/VideoDatail',
      component: VideoDatail,
      name: 'VideoDatail',
      meta: {
        login_required: true
      },
    },
    {
      path: '/Find',
      component: Find,
      name: 'Find'
    },
    {
      path: '/login',
      component: Login,
      name: 'login'
    },
    {
      path: '/zhuce',
      component: Zhuce,
      name: 'login'
    },
    {
      path: '/videoUP',
      component: VideoUP,
      name: 'VideoUP',
      meta: {
        login_required: true
      },
    },
    {
      path: '/Test',
      component: Test,
      name: 'Test'
    },
    {
      path: '/User',
      component: User,
      meta: {
        login_required: true
      },
      name: 'User'
    },
    {
      path: '/Comvideo',
      component: Comvideo,
      meta: {
        login_required: true
      },
      name: 'Comvideo'
    },
  ]

});


new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
Vue.use(ElementUI);

//路由拦截
router.beforeEach(function (to, from, next) {
  var logged_in = false
  var logged = window.localStorage.getItem('uid')
  if (logged != null) {
    logged_in = true
  }
  if (!logged_in && to.matched.some(function (item) {
      return item.meta.login_required
    })) {
    next('/login');
  } else {
    next();
  }
})
import moment from 'moment'
Vue.filter('dateFormat', function (dateStr,pattern = "YYYY-MM-DD HH:mm:ss") {
  return moment(dateStr).format(pattern);
})
Vue.filter('utp', function(value) {
  if(value=='1')
	return value='超级管理员';
  else if(value=='2')
	return value='管理员';
  else if(value=='3')
	return value='用户';
})

Vue.filter('date', function (value, fmt) {
  var dateTime = new Date(value);
  var o = {
      "M+": dateTime.getMonth() + 1,               //月份   
      "d+": dateTime.getDate(),                    //日   
      "h+": dateTime.getHours(),                   //小时   
      "m+": dateTime.getMinutes(),                 //分   
      "s+": dateTime.getSeconds(),                 //秒   
      "q+": Math.floor((dateTime.getMonth() + 3) / 3), //季度   
      "S": dateTime.getMilliseconds()             //毫秒   
  };

  if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (dateTime.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for (var k in o) {
      if (new RegExp(`(${k})`).test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
      }
  }
  return fmt;
})